package cn.tedu.charging.common.result;

import lombok.AccessLevel;
import lombok.Data;
import lombok.experimental.FieldDefaults;

@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
public class JsonResult <T> {
    Integer code;
    String msg;
    T data;

    public JsonResult(){

    }


    public JsonResult(StatusCode statusCode){
        this.code=statusCode.getCode();
        this.msg=statusCode.getMsg();

    }

    public JsonResult(StatusCode statusCode,T data){
        this.code=statusCode.getCode();
        this.msg=statusCode.getMsg();
        this.data=data;
    }


    public static <T> JsonResult<T> ok(T data){
        return new JsonResult<T>(StatusCode.SUCCESS,data);
    }


    public static <T> JsonResult<T> ok(){
        return ok(null);
    }

    public static <T> JsonResult<T> notok(T data){
        return new JsonResult<T>(StatusCode.FAIL,data);
    }

    public static <T> JsonResult<T> notok(){
        return notok(null);
    }

}
